package com.hanhanxiaochong.zhongxiangchuanmei.view;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Handler;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.mob.MobSDK;
import com.tencent.bugly.crashreport.CrashReport;

/**
 * Created by RockPhoenix on 2018/5/18.
 */

public class MyApplication extends MultiDexApplication {

    private static final String LOG_TAG = "MyApplication";
    private static MyApplication instance;
    protected static Handler handler;
    protected static int mainThreadId;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        handler = new Handler();
        mainThreadId = android.os.Process.myTid();
        MobSDK.init(this);
        //初始化Bugly
        CrashReport.initCrashReport(getApplicationContext(), getString(R.string.bugly_app_id), true);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }

    public static MyApplication instance() {
        return instance;
    }

    /**
     * 获取全局handler
     *
     * @return 全局handler
     */
    public static Handler getHandler() {
        return handler;
    }

    /**
     * 获取主线程id
     *
     * @return 主线程id
     */
    public static int getMainThreadId() {
        return mainThreadId;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        System.exit(0);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
